package com.cloud.zhimao.common.config.filter;


import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 图片过滤器
 */
//@WebFilter(filterName = "ImageFilter", urlPatterns = "/a/q/upload/download/*")
public class ImageFilter implements Filter {



    private static final List<String> IMAGE_TYPE_LIST = Arrays.asList("bmp","jpg","png",
            "tif","gif","pcx","tga","exif","fpx","svg","psd","cdr",
            "pcd","dxf","ufo","eps","ai","raw","WMF","webp","pdf");


    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        String Uri = ((HttpServletRequest) request).getRequestURI();
        String[] arr = Uri.split("/");
        String fileName = arr[arr.length - 1];

        String[] nameArr = fileName.split("\\.");
        if(IMAGE_TYPE_LIST.contains(nameArr[nameArr.length - 1])) {
            //fileService.downloadImage((HttpServletResponse) response, fileName);
        } else {
            chain.doFilter(request, response);
        }
    }
}
